/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package UI;

import BL.BLViaticoPorDia;
import DA.Utils;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Daniel.Cerdas
 */
public class FrmDiaViatico extends javax.swing.JFrame {

    /**
     * Creates new form FrmDiaViatico
     */
    static int consecutivo=0;
    static DefaultTableModel ModeloTabla;
    static JTable Tabla;
    public FrmDiaViatico(int valor) {
        initComponents();
        consecutivo=valor;
        cargarComboCantones();
        cargarComboCentroCostos();
        LblConsecutivo.setText(""+consecutivo);
      
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LblFecha = new javax.swing.JLabel();
        LblCanton = new javax.swing.JLabel();
        LblHoraEntrada = new javax.swing.JLabel();
        LblHoraSalida = new javax.swing.JLabel();
        LblDesayuno = new javax.swing.JLabel();
        LblAlmuerzo = new javax.swing.JLabel();
        LblCena = new javax.swing.JLabel();
        LblHospedaje = new javax.swing.JLabel();
        LblCentroCosto = new javax.swing.JLabel();
        LblEtiqueta = new javax.swing.JLabel();
        LblConsecutivo = new javax.swing.JLabel();
        TxtHoraEntrada = new javax.swing.JFormattedTextField();
        CmbCanton = new javax.swing.JComboBox();
        TxtFecha = new javax.swing.JFormattedTextField();
        TxtHoraSalida = new javax.swing.JFormattedTextField();
        TxtDesayuno = new javax.swing.JTextField();
        TxtCena = new javax.swing.JTextField();
        TxtAlmuerzo = new javax.swing.JTextField();
        TxtHospedaje = new javax.swing.JTextField();
        CmbCentroCosto = new javax.swing.JComboBox();
        BtnAgregar = new javax.swing.JButton();
        BtnCancelar = new javax.swing.JButton();
        LblNumero1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Desglose de Gasto Diario");
        setMinimumSize(new java.awt.Dimension(400, 300));
        setPreferredSize(new java.awt.Dimension(430, 620));

        LblFecha.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblFecha.setText("Fecha");

        LblCanton.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblCanton.setText("Canton");

        LblHoraEntrada.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblHoraEntrada.setText("Hora Entrada");

        LblHoraSalida.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblHoraSalida.setText("Hora Salida");

        LblDesayuno.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblDesayuno.setText("Desayuno");

        LblAlmuerzo.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblAlmuerzo.setText("Almuerzo");

        LblCena.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblCena.setText("Cena");

        LblHospedaje.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblHospedaje.setText("Hospedaje");

        LblCentroCosto.setFont(new java.awt.Font("Segoe UI Light", 0, 11)); // NOI18N
        LblCentroCosto.setText("Centro de Costo");

        LblEtiqueta.setFont(new java.awt.Font("Segoe UI Light", 1, 24)); // NOI18N
        LblEtiqueta.setText("Desglose de Gasto Diario");

        LblConsecutivo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        LblConsecutivo.setText("##");

        TxtHoraEntrada.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));
        TxtHoraEntrada.setText("00:00 pm");
        TxtHoraEntrada.setToolTipText("");
        TxtHoraEntrada.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        CmbCanton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CmbCanton.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        TxtFecha.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        TxtFecha.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        TxtHoraSalida.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));
        TxtHoraSalida.setText("00:00 am");
        TxtHoraSalida.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        TxtDesayuno.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtDesayuno.setText("0");

        TxtCena.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtCena.setText("0");

        TxtAlmuerzo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtAlmuerzo.setText("0");

        TxtHospedaje.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtHospedaje.setText("0");

        CmbCentroCosto.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        CmbCentroCosto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        BtnAgregar.setFont(new java.awt.Font("Segoe UI Light", 0, 11)); // NOI18N
        BtnAgregar.setText("Agregar");
        BtnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAgregarActionPerformed(evt);
            }
        });

        BtnCancelar.setFont(new java.awt.Font("Segoe UI Light", 0, 11)); // NOI18N
        BtnCancelar.setText("Cancelar");
        BtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCancelarActionPerformed(evt);
            }
        });

        LblNumero1.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblNumero1.setText("Numero");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(LblEtiqueta))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(200, 200, 200)
                        .addComponent(TxtAlmuerzo, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(200, 200, 200)
                        .addComponent(TxtCena, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(200, 200, 200)
                        .addComponent(TxtHospedaje, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(LblCanton)
                            .addComponent(LblNumero1)
                            .addComponent(LblFecha)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(LblDesayuno)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(LblCena)
                                        .addComponent(LblAlmuerzo)))
                                .addGap(8, 8, 8))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(LblHospedaje)
                                    .addComponent(LblCentroCosto)
                                    .addComponent(BtnAgregar))
                                .addGap(5, 5, 5)))
                        .addGap(18, 18, 18)
                        .addComponent(TxtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(125, 125, 125)
                        .addComponent(LblHoraSalida)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(BtnCancelar)
                            .addComponent(LblConsecutivo)
                            .addComponent(TxtHoraSalida, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(CmbCanton, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(CmbCentroCosto, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(LblHoraEntrada)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TxtHoraEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TxtDesayuno, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(115, 115, 115))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(LblEtiqueta)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LblConsecutivo)
                    .addComponent(LblNumero1))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LblFecha)
                    .addComponent(TxtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CmbCanton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblCanton))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtHoraSalida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblHoraSalida))
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(TxtHoraEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblHoraEntrada))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtDesayuno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblDesayuno))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtAlmuerzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblAlmuerzo))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtCena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblCena))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtHospedaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblHospedaje))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CmbCentroCosto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LblCentroCosto))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnAgregar)
                    .addComponent(BtnCancelar))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BtnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAgregarActionPerformed
        // TODO add your handling code here:
       
     //   Date Fecha1=Date.valueOf(TxtFecha.toString());
        int idCanton=BLViaticoPorDia.ObtenerIDCanton(CmbCanton.getSelectedItem().toString());
        ModeloTabla.addRow(new Object[]{TxtFecha.getText(),idCanton,TxtHoraEntrada.getText(),
        TxtHoraSalida.getText(),TxtDesayuno.getText(),TxtAlmuerzo.getText(),TxtCena.getText(),TxtHospedaje.getText(),0,CmbCentroCosto.getSelectedItem().toString(),consecutivo,"X"});

        Tabla.setModel(ModeloTabla);
         this.setVisible(false);
    }//GEN-LAST:event_BtnAgregarActionPerformed

    private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelarActionPerformed
        // TODO add your handling code here:
        TxtAlmuerzo.setText("");
        TxtDesayuno.setText("");
        TxtCena.setText("");
        TxtFecha.setText("");
        TxtHoraEntrada.setText("");
        TxtHoraSalida.setText("");
        TxtHospedaje.setText("");
        this.setVisible(false);
    }//GEN-LAST:event_BtnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmDiaViatico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmDiaViatico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmDiaViatico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmDiaViatico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmDiaViatico(consecutivo).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAgregar;
    private javax.swing.JButton BtnCancelar;
    private javax.swing.JComboBox CmbCanton;
    private javax.swing.JComboBox CmbCentroCosto;
    private javax.swing.JLabel LblAlmuerzo;
    private javax.swing.JLabel LblCanton;
    private javax.swing.JLabel LblCena;
    private javax.swing.JLabel LblCentroCosto;
    private javax.swing.JLabel LblConsecutivo;
    private javax.swing.JLabel LblDesayuno;
    private javax.swing.JLabel LblEtiqueta;
    private javax.swing.JLabel LblFecha;
    private javax.swing.JLabel LblHoraEntrada;
    private javax.swing.JLabel LblHoraSalida;
    private javax.swing.JLabel LblHospedaje;
    private javax.swing.JLabel LblNumero1;
    private javax.swing.JTextField TxtAlmuerzo;
    private javax.swing.JTextField TxtCena;
    private javax.swing.JTextField TxtDesayuno;
    private javax.swing.JFormattedTextField TxtFecha;
    private javax.swing.JFormattedTextField TxtHoraEntrada;
    private javax.swing.JFormattedTextField TxtHoraSalida;
    private javax.swing.JTextField TxtHospedaje;
    // End of variables declaration//GEN-END:variables

    private void cargarComboCantones() {
        CmbCanton.removeAllItems();
        CmbCanton=BLViaticoPorDia.ListaCantones(CmbCanton);
        }
    
  
    private void cargarComboCentroCostos() {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        CmbCentroCosto.removeAllItems();
        CmbCentroCosto=BLViaticoPorDia.ListaCentroCosto(CmbCentroCosto);
    }

   public TableModel getModeloTabla() {
        return ModeloTabla;
    }

    public static void setModeloTabla(TableModel ModeloTabla) {
        FrmDiaViatico.ModeloTabla = (DefaultTableModel) ModeloTabla;
    }

    void setTabla(JTable TblViaticosDia) {
       
       ModeloTabla= (DefaultTableModel) TblViaticosDia.getModel(); //To change body of generated methods, choose Tools | Templates.
       Tabla=TblViaticosDia;
    }
    
}
